<?php

use Sc\Util\HtmlStructure\Html\Html;
/** @var $code */


Html::create("代码");
Html::css()->load('https://unpkg.com/codemirror@5.65.14/lib/codemirror.css');
Html::css()->load('https://unpkg.com/codemirror@5.65.14/theme/material.css');
Html::css()->load('https://unpkg.com/codemirror@5.65.14/addon/dialog/dialog.css');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/lib/codemirror.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/addon/dialog/dialog.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/addon/edit/closebrackets.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/addon/search/jump-to-line.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/addon/search/searchcursor.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/addon/search/search.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/mode/sql/sql.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/mode/clike/clike.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/mode/php/php.js');
Html::js()->load('https://unpkg.com/codemirror@5.65.14/mode/javascript/javascript.js');
Html::loadAdminUtilJs();

$editor = h('textarea', ['id' => 'editor'])->append();


$data = base64_encode($code);
Html::js()->defCodeBlock(<<<JS
var editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
    lineNumbers: true,
    // mode: 'application/x-httpd-php',
    mode: 'text/x-php',
    theme: 'material',
    lineWrapping: true,
    autofocus: true,
    smartIndent: true,
    matchBrackets: true,
    autoCloseBrackets: true,
});
editor.setSize('auto', window.innerHeight - 20);
editor.setValue(AdminUtil.base64Decode('$data'))
JS);

return $editor;